package com.catmiw.wyz.util;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.Workbook;

public class ExcelUtils {
	public static Workbook getWorkbook(String filename) {
		POIFSFileSystem fs = null;
		FileInputStream fi=null;
		Workbook wb = null;
		try {
			fi=new FileInputStream(filename);
			fs = new POIFSFileSystem(fi);
			wb = new HSSFWorkbook(fs);

		} catch (IOException e) {
			e.printStackTrace();
		} finally{
			if (fi!=null){
				try {
					fi.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}

		return wb;
	}

	public static void writeWorkbook(Workbook wb,String filename) {
		FileOutputStream fileOut = null;
		try {
			fileOut = new FileOutputStream(filename);
			wb.write(fileOut);
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				fileOut.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
